﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;

using Padelcenter.Common;
using Padelcenter.DataAccess;

namespace Padelcenter.BusinessLogic.Get
{
    public class GetMedia : IBusinessLogic
    {
        public GetMedia() { }

        public void Invoke()
        {
            Media_Select oMediaSelect = new Media_Select();
            oMediaSelect.Media = this.Media;

            this.Resultset = oMediaSelect.Get();
        }

        public List<Media> MediaList()
        {
            this.Invoke();

            List<Media> listaMedia = new List<Media>();

            DataTable dTable = new DataTable();
            dTable = this.Resultset.Tables[0];

            if (dTable.Rows.Count > 0)
            {
                Media oMedia;

                foreach (DataRow r in dTable.Rows)
                {
                    oMedia = new Media();
                    oMedia.IdMedia = Convert.ToInt32(r["idMedia"]);

                    TipoMedia oTipoMedia = new TipoMedia();
                    oTipoMedia.IdTipoMedia = Convert.ToInt32(r["idTipoMedia"]);

                    GetTipoMedia oGetTipoMedia = new GetTipoMedia();
                    oGetTipoMedia.TipoMedia = oTipoMedia;

                    oMedia.TipoMedia = oGetTipoMedia.TipoMediaList()[0];
                    
                    oMedia.Activo = Convert.ToBoolean(r["Activo"]);

                    listaMedia.Add(oMedia);
                }
            }

            return listaMedia;
        }

        private DataSet _resultset;
        private Media _media;

        public Media Media
        {
            get { return _media; }
            set { _media = value; }
        }

        public DataSet Resultset
        {
            get { return _resultset; }
            set { _resultset = value; }
        }
    }

}
